﻿using System;
using System.Net.Mail;
using System.Text;

namespace Guru.Framework.Util
{
    public class MailUtil
    {
        public static void SendMail(string host, int port, string sourceMail, string sourcepass, string destinationMail, string subject, string body)
        {
            try
            {
                SmtpClient client = new SmtpClient();
                client.Port = port;
                client.Host = host;
                client.EnableSsl = true;
                client.Timeout = 10000;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential(sourceMail, sourcepass);

                MailMessage mm = new MailMessage(sourceMail, destinationMail, subject, body);
                mm.BodyEncoding = UTF8Encoding.UTF8;
                mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

                client.Send(mm);
            }
            catch (Exception)
            {
                throw;
            }
        }


        public static bool IsValidEMail(string email)
        {
            try
            {
                MailAddress mailAddr = new MailAddress(email);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
